<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册--四川大学科技成果转化平台</title>
		<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
		<link rel="stylesheet" href="../css/register.css" />
	</head>
	<body>
	<!-- header顶部标语、登陆注册 -->
	<header>
		<div class="header-top">
			<div class="container">
				<div class="row">
					<div class="header-top-left">
						<div class="welcome-msg"><span>欢迎来到四川大学科技成果交易平台!</span></div>
					</div>
					<div class="header-top-right">
						<ul class="header-links">
							<li><a href="http://123.207.115.103:8100/index">首页</a></li>
							<li><a href="http://123.207.115.103:8100/about">关于</a></li>
                		</ul>
					</div>
				</div>
			</div>
		</div>
	</header>
	<div class="content">
		<div class="form">
			<div id="form-register" method="post">
				<p class="form-type">创建账户</p>
				<label>
					<span class="title">密码:</span>
					<span class="field"><input type="password" placeholder="数字和字母组成，长度8-20位" name="password" id="credential"></span>
				</label>
				<label>
					<span class="title">确认密码:</span>
					<span class="field"><input type="password" placeholder="数字和字母组成，长度8-20位" name="passwordConfirm" id="credentialConfirm"></span>
				</label>
				<label>
					<span class="title">验证您的手机号码:</span>
					<span class="field"><input id="identifier" class="short"type=" text"placeholder="手机号码" name="identifier"></span>
					<span><button class="short-button" id="getVericode" onclick="getVerify()">发送验证码</button></span>
				</label>
				<label>
					<span class="title">验证码:</span>
					<span class="field"><input type="text" id="verifycode"  name="verifycode"></span>
				</label>
				<div class="to-continue">
					<button class="style-bottom" id="btn-register">继续</button>
					<input type="text" value="telephone" name="type" id="type" hidden="hidden" />
				</div>
			</div>
		</div>
	</div>
	<footer>
		<div class="footer-middle">
			<div class="container">
				<div class="row">
					版权所有：Copyright © 2018 WSN
				</div>
			</div>
		</div>
	</footer>

	<script>
        var randomNumber;
        var phone ;
        $(document).ready(function() {
            $("#identifier").bind('input porpertychange',function () {
                phone = $("#identifier").val();
            });
        });

        function getVerify() {
            var num = 8999;
            var top = 9999;
            var bottom = 1000;
            num = parseInt(Math.random() * (top - bottom + 1) + bottom);
            randomNumber = num;
            $.post("http://111.231.223.47:8035/message", {verifyCode: num, phoneNumber: phone},function(data){
                alert(data);
            });
            var i=59;
            $("#getVericode").attr("disabled", true);
            var time=setInterval(function () {
                $("#getVericode").html(i+"s后重新获取");
                i--;
            },1000);
            setTimeout(function(){//两秒后跳转
                clearInterval(time);
                $("#getVericode").html("获取验证码");
                $("#getVericode").attr("disabled", false);
            },60000);
        }
        function check() {

            var verifycode = $("#verifycode").val();
            var phone = $("#identifier").val();
            if( verifycode == ""){
                alert("验证码为空");
                return false;
            }
            if(phone == ""){
                alert("手机号为空");
                return false;
            }
            if (verifycode == randomNumber) {
                //
                return true;
            } else {
                alert("验证码错误");
                return false;
            }
        }

        $("#btn-register").click(function () {
            var data={"identifier":$("#identifier").val(),"credential":$("#credential").val(),"credentialConfirm":$("#credentialConfirm").val(),"type":$("#type").val()};
            console.log(data)
            if(check()){//
                $.ajax({
                    type: 'post',
                    url:'register',
                    data:data,
                    success: function (data) {
                        if("注册成功"==data){
                            console.log(data)
                            alert(data+",2s后到登录页");
                            $(".alert").html(data+",2s后到登录页");
                            setTimeout(function () {
                                location.href="/signIn";
                            },2000);
                        }else{
                            alert(data)
                            console.log(data)
                        }
                    },
                    error: function () {
                    }
                });
            }
        });
	</script>
	</body>
</html>
